﻿create PROCEDURE Sync.SP_LoanCancellingDebts_SelectChanges
@LastRowVersion rowversion,
@FilterdColumn UNIQUEIDENTIFIER
AS 
BEGIN 
	SELECT 
        t.[LoanCancellingDebtID],
		g.[LoanID],g.[Notes],
		t.IsDeleted,
		t.LastUpdatedDate
	FROM [dbo].[LoanCancellingDebts] g RIGHT JOIN Sync.LoanCancellingDebts_Tracking t  
    ON t.LoanCancellingDebtID = g.LoanCancellingDebtID 
    join CustomerLoans cl
	on g.LoanID = cl.LoanID
	WHERE (@LastRowVersion IS NULL OR t.Version > @LastRowVersion)
	AND ((@FilterdColumn IS NULL) OR (cl.CommitteeID = @FilterdColumn))
    END











